package cn.ctodb.cms.service.mapper;

import cn.ctodb.cms.domain.*;
import cn.ctodb.cms.service.dto.CmsContentDTO;

import org.mapstruct.*;
import java.util.List;

/**
 * Mapper for the entity CmsContent and its DTO CmsContentDTO.
 */
@Mapper(componentModel = "spring", uses = {CmsTagMapper.class, })
public interface CmsContentMapper {

    @Mapping(source = "channel.id", target = "channelId")
    CmsContentDTO cmsContentToCmsContentDTO(CmsContent cmsContent);

    List<CmsContentDTO> cmsContentsToCmsContentDTOs(List<CmsContent> cmsContents);

    @Mapping(target = "txts", ignore = true)
    @Mapping(target = "imgs", ignore = true)
    @Mapping(target = "files", ignore = true)
    @Mapping(source = "channelId", target = "channel")
    CmsContent cmsContentDTOToCmsContent(CmsContentDTO cmsContentDTO);

    List<CmsContent> cmsContentDTOsToCmsContents(List<CmsContentDTO> cmsContentDTOs);

    default CmsChannel cmsChannelFromId(Long id) {
        if (id == null) {
            return null;
        }
        CmsChannel cmsChannel = new CmsChannel();
        cmsChannel.setId(id);
        return cmsChannel;
    }

    default CmsTag cmsTagFromId(Long id) {
        if (id == null) {
            return null;
        }
        CmsTag cmsTag = new CmsTag();
        cmsTag.setId(id);
        return cmsTag;
    }
}
